﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;
using System.Data;
using MovieRental.SqlRepositoryLibrary.Helpers;
using MovieRental.Entities;

namespace MovieRental.SqlRepositoryLibrary.Converters
{
    public class DiscountConverter : BaseConverter<DiscountInfo, Guid>
    {
        protected override SqlEntityMapping SetUpMapping()
        {
            var mapping = new SqlEntityMapping("Discounts", "Id");
            mapping.AddProperty("Id", "Id", SqlDbType.UniqueIdentifier);
            mapping.AddProperty("Value", "Value", SqlDbType.Float);
            return mapping;
        }

        protected override void SetUpPropertyValues(DiscountInfo entity)
        {
            SetProperty("Id", entity.Id);
            SetProperty("Value", entity.Value);
        }

        public override DiscountInfo ConvertFromDataReader(SqlDataReader reader)
        {
            Guid id = (Guid) GetValueForProperty(reader, "Id");
            DiscountInfo discount = new DiscountInfo(id);
            discount.Value = (double)GetValueForProperty(reader, "Value");
            return discount;
        }
    }
}
